package com.yonyou.brigade.third_parties.ctrip.bigcustomer.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.ctrip.bigcustomer.service.ICtripBCReauthorizationPersionService;
import com.yonyou.brigade.third_parties.ctrip.bigcustomer.util.DeptAuth;
import org.opensaml.xml.signature.J;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ctrip/reauth")
public class CtripBCReauthorizationPersionController {

    private static Logger logger = LoggerFactory.getLogger(CtripBCReauthorizationPersionController.class);

    @Autowired
    IBriChannelService briChannelService;

    @Autowired
    ICtripBCReauthorizationPersionService ctripBCReauthorizationPersionService;

    @RequestMapping(value="/updateUserInfos" , method = RequestMethod.POST)
    public String updateDeptAuth(@RequestBody JSONObject params){
        logger.info("updateUserInfos's param:" + JSON.toJSONString(params));
        JSONObject result = null;
        String userid = params.getString("userid");
        String username=params.getString("username");
        String orgpk = params.getString("orgpk");
        String email = params.getString("email");
//        if(departments!=null&&departments.size()>0) {
//            for(int i=0;i<departments.size();i++) {
//                JSONObject jsonObject=departments.getJSONObject(i);
//                DeptAuth deptAuth=new DeptAuth();
//                deptAuth.setUserid(userid);
//                deptAuth.setUsername(username);
//                deptAuth.setDeptname(jsonObject.getString("deptname"));
//                deptAuth.setDeptpk(jsonObject.getString("deptpk"));
//                deptAuth.setOrgpk(orgpk);
//                deptAuths.add(deptAuth);
//            }
//        }
        String tenantid = params.getString("tenantid");
        List<String> userids;
        userids = (List<String>) params.get("userids");
        result = ctripBCReauthorizationPersionService.updateUserInfos(orgpk , tenantid , userids , email);
        return JSON.toJSONString(result);
    }
}
